<div class="rightcontent rc-bg-grey">
    <div class="rc-pagepadding layui-form">
        <div class=" rc-pannel rc-pagepadding">
            <div class="rc-pannel-header  ">
                <div class="title ">审核意见</div>
            </div>
            <div class="rc-pannel-body  rc-pagepadding  ">
                <form id="pendingform">
                    <div class="layui-inline ">
                        <label class="layui-form-label">审核结果</label>
                        <div class="layui-input-inline ">

                            <input type="radio" name="status" value="1" title="通过" checked>

                            <input type="radio" name="status" value="-1" title="退回">


                        </div>
                    </div>

                    <div class="layui-inline ">
                        <label class="layui-form-label">审核意见</label>
                        <div class="layui-input-inline ">
                            <input type="text" name="opinion" placeholder="" value="<?php echo request()->get('opinion', ''); ?>" autocomplete="off" class="layui-input">
                        </div>
                    </div>



                    <div class="layui-inline ">

                        <div class="layui-input-inline ">
                            <button type="button" id="dopending_btn" class="layui-btn layui-btn-sm layui-btn-primary " style="margin-left: 30px;">确定</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>


        <div class=" rc-pannel rc-pagepadding rc-margin-top-default">
            <div class="rc-pannel-header  ">
                <div class="title ">文章内容</div>
            </div>
            <div class="rc-pannel-body ">
                <form id="contentform">
                    <div class="rc-flex">
                        <div class="rc-flex1 rc-pagepadding">


                            <div class="layui-form-item">
                                <label class="layui-form-label element_title">栏目：</label>
                                <div class="layui-input-block" style="line-height: 30px;">
                                    <?php echo $cateinfo['title']; ?>

                                    <input type="hidden" value="<?php echo request()->get('cid') ?>" name="cid" />

                                </div>

                            </div>

                            <?php
                            if (isset($fields[1])) {
                                foreach ($fields[1] as $field) {
                            ?>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label element_title"><?php echo $field['title'] ?>：</label>
                                        <div class="layui-input-block">

                                            <?php
                                            $element = $field['element'];
                                            unset($field['element']);
                                            $field['value'] = $contentinfo[$field['name']];
                                            unset($field['id']);
                                            echo element($element, ...$field);

                                            ?>
                                        </div>

                                    </div>
                            <?php
                                }
                            } ?>


                            <!---  设置标签  --->
                            <?php
                            if ($tags) {
                            ?>

                                <div class="layui-form-item">
                                    <label class="layui-form-label element_title">标签：</label>
                                    <div class="layui-input-block">

                                        <?php
                                        foreach ($tags as $tag) {
                                        ?>
                                            <input type="checkbox" <?php echo in_array($tag['id'], $contenttagids) ? 'checked' : '' ?> value="<?php echo $tag['id'] ?>" name="tag[]" title="<?php echo $tag['tag'] ?>" autocomplete="off" />
                                        <?php
                                        }
                                        ?>
                                    </div>

                                </div>
                            <?php
                            }
                            ?>





                        </div>
                        <div style="width: 240px;border-left:1px solid #ccc ">

                            <?php
                            if (isset($fields[2])) {
                                foreach ($fields[2] as $field) {

                            ?>
                                    <div class="layui-form-item rc-pagepadding" style="border-bottom: 1px solid #ccc;">
                                        <div style="margin-bottom: 15px;" class="element_title">
                                            <?php echo $field['title'] ?>
                                        </div>

                                        <div style="text-align: center;">
                                            <?php
                                            $element = $field['element'];
                                            unset($field['element']);
                                            $field['value'] =  $contentinfo[$field['name']];
                                            unset($field['id']);
                                            echo element($element, ...$field) ?>
                                        </div>

                                    </div>
                            <?php
                                }
                            } ?>


                            <div class="layui-form-item rc-pagepadding" style="border-bottom: 1px solid #ccc;">
                                <div style="margin-bottom: 15px;" class="element_title">
                                    浏览量
                                </div>

                                <div style="text-align: center;">
                                    <?php echo element('input', name: 'viewscount', value: $contentinfo['viewscount']); ?>
                                </div>

                            </div>

                            <div class="layui-form-item rc-pagepadding" style="border-bottom: 1px solid #ccc;">

                                <div style="margin-bottom: 15px;" class="element_title">
                                    是否允许评论/点赞/收藏
                                </div>
                                <div style="margin-bottom: 15px;" class="">
                                    <input type="radio" name="interacttype" title="跟随栏目" lay-filter="interacttype" value="1" <?php echo $contentinfo['interacttype'] == 1 ? 'checked' : ''; ?> autocomplete="off" />
                                    <input type="radio" name="interacttype" title="自定义" lay-filter="interacttype" value="2" <?php echo $contentinfo['interacttype'] == 2 ? 'checked' : ''; ?> autocomplete="off" />
                                </div>


                                <div style="text-align: center;display:none" id="interactcustom">
                                    <input type="checkbox" name="comment" title="评论" autocomplete="off" value="1" <?php echo $contentinfo['interacttype'] == 1 && $contentinfo['comment'] == 1 ? 'checked' : ''; ?> autocomplete="off" />
                                    <input type="checkbox" name="like" title="点赞" autocomplete="off" value="1" <?php echo $contentinfo['interacttype'] == 1 && $contentinfo['like'] == 1 ? 'checked' : ''; ?> autocomplete="off" />
                                    <input type="checkbox" name="collect" title="收藏" autocomplete="off" value="1" <?php echo $contentinfo['interacttype'] == 1 && $contentinfo['collect'] == 1 ? 'checked' : ''; ?> autocomplete="off" />
                                </div>

                            </div>

                        </div>
                    </div>
                </form>
            </div>
        </div>

    </div>
</div>

<input type="hidden" id="nextcid" value="<?php echo $nextcontent ? $nextcontent['cid'] : ($prevcontent ? $prevcontent['cid'] : 0); ?>" />
<input type="hidden" id="nextid" value="<?php echo $nextcontent ? $nextcontent['id'] : ($prevcontent ? $prevcontent['id'] : 0); ?>" />


<script type='text/javascript'>
    layui.use(function() {

        var form = layui.form;
        var layer = layui.layer;

        form.on('radio(interacttype)', function(data) {

            var elem = data.elem; // 获得 radio 原始 DOM 对象
            var checked = elem.checked; // 获得 radio 选中状态
            var value = elem.value; // 获得 radio 值
            var othis = data.othis; // 获得 radio 元素被替换后的 jQuery 对象

            if (value == 2) {
                $('#interactcustom').show();
            } else {
                $('#interactcustom').hide();
            }

        });

        function serializeObject(obj) {
            var result = {}; // 准备一个空对象
            var params = obj.serializeArray();
            $.each(params, function(index, value) {
                result[value.name] = value.value;
            })
            return result; // 将处理的结果返回到函数外部
        }




        $('#dopending_btn').click(function() {

            $.ajax({
                url: '/app/cms/admin/Index/doPending?id=<?php echo request()->get('id') ?>&cid=<?php echo request()->get('cid') ?>', //请求路径
                type: "POST", //请求方式
                data: {
                    pendingform: serializeObject($('#pendingform')),
                    contentform: serializeObject($('#contentform'))
                }, // 默认写法
                success: function(data) {
                    if (data.code == 0) {
                        var tiptitle = '审核成功，自动进入下一篇文章'
                        if ($('#nextcid').val() == 0) {
                            tiptitle = '审核成功';
                        }
                        toastr_success(tiptitle, function() {

                            if ($('#nextcid').val() != 0) {
                                window.location.href = '/app/cms/admin/Index/doPending?cid=' + $('#nextcid').val() + '&id=' + $('#nextid').val();
                            } else {
                                window.parent.location.reload();
                            }
                        });
                    } else {
                        toastr_error(data.message);
                    }
                },
                error: function() {

                },

            });

        });



    });
</script>